﻿using Furion.Logging.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure.Internal;
using Pomelo.EntityFrameworkCore.MySql.Migrations;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.EntityFramework.Core
{
    public class ExtendedSqlGenerator : MySqlMigrationsSqlGenerator
    {
        public ExtendedSqlGenerator([NotNull] MigrationsSqlGeneratorDependencies dependencies, [NotNull] IRelationalAnnotationProvider annotationProvider, [NotNull] IMySqlOptions options)
            : base(dependencies, annotationProvider, options)
        {
        }

        protected override void Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true)
        {
            // 级联关系控制
            RemoveForeignKeysHelper.ExecuForeignKeys(operation, model);
            base.Generate(operation, model, builder, terminate);
        }
    }
}
